<!DOCTYPE html>
<html  class="x-admin-sm">
<#include "../layout/meta.ftl">
<body class="layui-layout-body">
<div style="margin: 2vw">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>项目列表</legend>
    </fieldset>
    <form class="layui-form layui-col-space5" id="search-form">
        <div class="layui-input-inline layui-show-xs-block">
            <input type="text" id="name" placeholder="输入项目名称查询" name="name" placeholder="" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline layui-show-xs-block">
            <button class="layui-btn layui-btn-normal" lay-submit="search" lay-filter="search">
                <i class="layui-icon">&#xe615;</i></button>
            <button type="button" lay-submit="addProject" lay-filter="addProject" class="layui-btn layui-btn-normal">新增</button>
        </div>
    </form>
    <table class="layui-hide" id="project" lay-filter="project"></table>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="desc">详情</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="del">删除</a>
</script>
<script>
    //JavaScript代码区域
    layui.use(['element','table','form'], function(){
        let element = layui.element,table = layui.table,form=layui.form;

        tableId=table.render({
            elem: '#project'
            ,url:'/project/getProjectList'
            ,method:'get'
            ,contentType:'application/json'
            ,height:"full-110"
            ,cols: [[
                {field:'name',width: '20%', title: '项目名称',unresize:true}
                ,{field:'uuid',width: '20%', title: 'UUID',unresize:true}
                ,{field:'url', title: '项目地址',unresize:true}
                ,{fixed: 'right',width: '20%',  title:'操作', toolbar: '#barDemo',unresize:true}
            ]]
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": res.message, //解析接口状态
                    "data": res.data, //解析数据列表
                    "count": res.data.total, //解析数据长度
                };
            }
            ,
            done: function (res, curr, count) {
                exportData=res.data;
            }
        });
        //监听提交
        form.on('submit(search)', function (data) {
            debugger;
            tableId.reload({
                where: {
                    name:data.field.name
                }
            });
            return false;
        });
        //监听提交
        form.on('submit(addProject)', function (data) {
            xadmin.open('新增','/project/projectAddOrEdit/0',null, null);
            return false;
        });
        //监听工具条
        table.on('tool(project)', function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "desc": xadmin.open('查看详情','/project/projectDesc/'+data.uuid,null, null);break;
                case "edit":xadmin.open('编辑','/project/projectAddOrEdit/'+data.uuid,null, null);break;
                case "del":projectDel(data.uuid);break;
            }
        });
        function projectDel(uuid) {
            layer.alert("确定删除",function () {
                $.ajax({
                    url:"/project/del/"+uuid,
                    type:"get",
                    success:function (res) {
                        location.reload();
                    }
                });
            })
        }

    });
</script>
</body>
</html>